home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 34 / Mac Magazin and MacEasy Magazine CD - Issue 34.iso / Grafik & Text / Alpha ƒ / Tcl / UserCode / bibtexOtherAux.tcl next >
Text File  |  1997-05-03  |  6KB  |  187 lines

  1. ######################################################################
  2. # File:    bibtexOtherAux.tcl
  3. # Author:  Pierre Basso <Pierre.Basso@lim.univ-mrs.fr>
  4. # This utility adds a command called "bibtex file.?.aux" 
  5. # to the Typeset submenu of the LaTeX menu.  This command 
  6. # processes .aux files created by the bibunits package 
  7. # documented on pages 386--391 of _The LaTeX Companion_ by 
  8. # Goossens, Mittelbach, and Samarin [Addison-Wesley, 1994].
  9. # To install this utility, do the following:
  10. #     1) Open a .tex file.
  11. #     
  12. #     2) Pull down the Config menu and choose the command
  13. #      "Current Mode:Edit Prefs".
  14. #     
  15. #     3) Insert the line
  16. #     
  17. #          source "$HOME:Tcl:UserCode:bibtexOtherAux.tcl"
  18. #     
  19. #        into TeXPrefs.tcl.
  20. #     
  21. #     4) Restart Alpha.
  22. # After adding the 'source' line to TeXPrefs.tcl, the command 
  23. # will be automatically inserted into the Typeset submenu 
  24. # every time TeX mode is initialized.  To disable this utility, 
  25. # remove the 'source' line from TeXPrefs.tcl.
  26. ######################################################################
  27.  
  28. # Return a modified "Typeset" submenu.
  29. proc typesetSubmenu {} {
  30.     global mode
  31.     set currentWin [lindex [winNames -f] 0]
  32.     if { $currentWin == "" } {
  33.         return [minimalTypesetSubmenu]
  34.     } elseif { $mode == "TeX" } {
  35.         set currentDoc [file tail $currentWin]
  36.         # Process an untitled window:
  37.         if { [set num [winUntitled]] } {
  38.             if { $num > 1 } { set currentDoc "Untitled$num" }
  39.             # fall through
  40.         }
  41.     } else {
  42.         return [minimalTypesetSubmenu]
  43.     }
  44.     set docBasename [file rootname $currentDoc]
  45.     set projBasename $docBasename
  46.     set currentProj [isWindowInFileset $currentWin "tex"]
  47.     if {    $currentProj !=    "" } {
  48.         set currentDoc [file tail [texFilesetBaseName $currentProj]]
  49.         set docBasename [file rootname $currentDoc]
  50.     }
  51.     # Determine which menu items are dimmed:
  52.     foreach ext {DVI PS AUX IDX Selection} { set prefix$ext "" }
  53. #     if { [findAuxiliaryFile DVI] == "" } {
  54. #         set prefixDVI "("
  55. #     }
  56. #     if { [findAuxiliaryFile PS] == "" } {
  57. #         set prefixPS "("
  58. #     }
  59. #     if { [findAuxiliaryFile AUX] == "" } {
  60. #         set prefixAUX "("
  61. #     }
  62. #     if { [findAuxiliaryFile IDX] == "" } {
  63. #         set prefixIDX "("
  64. #     }
  65. #     if { ![isSelection] } {
  66. #         set prefixSelection "("
  67. #     }
  68.     return [list menu -M TeX -n Typeset -m -p typesetSubmenuFilter [list \
  69.         [list /TTypeset $currentDoc] \
  70.         [list <U<O/V${prefixDVI}View "$docBasename\.dvi"] \
  71.         [list <U<O/P${prefixDVI}Print "$docBasename\.dvi"] \
  72.         "(-" \
  73.         {<U<O/TTypeset Clipboard} \
  74.         [list ${prefixSelection}Typeset Selection] \
  75.         "(-" \
  76.         [list <S${prefixPS}Open "$docBasename\.ps"] \
  77.         [list <S${prefixDVI}dvips "$docBasename\.dvi"] \
  78.         [list ${prefixPS}View "$docBasename\.ps"] \
  79.         [list ${prefixPS}Print "$docBasename\.ps"] \
  80.         "(-" \
  81.         [list <SOpen "$docBasename\.bbl"] \
  82.         [list <S${prefixAUX}bibtex "$docBasename\.aux"] \
  83.         [list <E${prefixAUX}bibtex "$docBasename\.\?\.aux"] \
  84.         [list <SOpen "$docBasename\.ind"] \
  85.         [list <S${prefixIDX}makeindex "$docBasename\.idx"] \
  86.         "(-" \
  87.         [typesetOtherFilesSubmenu $docBasename $projBasename] \
  88.         "(-" \
  89.         {Remove Auxiliary Files…} \
  90.         {Remove Temporary Files} \
  91.         ]
  92.     ]
  93. }
  94.  
  95. proc typesetSubmenuFilter {submenu item} {
  96.     switch -regexp $item {
  97.         {Typeset Selection}  {set func "typesetSelection"}
  98.         {Typeset Clipboard}  {set func "typesetClipboard"}
  99.         "Typeset.*"  {set func "typeset"}
  100.         "View.*\.dvi$"  {set func {doTypesetCommand view DVI}}
  101.         "Print.*\.dvi$"  {set func {doTypesetCommand print DVI}}
  102.         "dvips.*\.dvi$"  {set func {doTypesetCommand dvips DVI}}
  103.         "View.*\.ps$"  {set func {doTypesetCommand view PS}}
  104.         "Print.*\.ps$"  {set func {doTypesetCommand print PS}}
  105.         {bibtex.*\.\?\.aux$}  {set func "bibtexOtherAuxiliary"}
  106.         "bibtex.*"  {set func {doTypesetCommand bibtex AUX}}
  107.         "makeindex.*"  {set func {doTypesetCommand makeindex IDX}}
  108.         "Open.*\.ps$"  {set func {doTypesetCommand open PS}}
  109.         "Open.*\.bbl$"  {set func {doTypesetCommand open BBL}}
  110.         "Open.*\.ind$"  {set func {doTypesetCommand open IND}}
  111.         "Open.*\.log$"  {set func {doTypesetCommand open LOG}}
  112.         "Open.*\.aux$"  {set func {doTypesetCommand open AUX 1}}
  113.         "Open.*\.aux $"  {set func {doTypesetCommand open AUX}}
  114.         "Open.*\.toc$"  {set func {doTypesetCommand open TOC}}
  115.         "Open.*\.lof$"  {set func {doTypesetCommand open LOF}}
  116.         "Open.*\.lot$"  {set func {doTypesetCommand open LOT}}
  117.         "Open.*\.idx$"  {set func {doTypesetCommand open IDX}}
  118.         "Open.*\.blg$"  {set func {doTypesetCommand open BLG}}
  119.         "Open.*\.ilg$"  {set func {doTypesetCommand open ILG}}
  120.         {Open Any TeX File}  {set func "openAnyTeXFile"}
  121.         {Remove Auxiliary Files}  {set func "removeAuxiliaryFiles"}
  122.         {Remove Temporary Files}  {set func "removeTemporaryFiles"}
  123.         default {set func $item}
  124.     }
  125.     eval $func
  126. }
  127.  
  128. proc bibtexOtherAuxiliary {} {
  129.  
  130.     # Test if many bibdata files
  131.     set auxiliaryfile [lindex [winNames -f] 0]
  132.     set rootauxiliaryfile [file rootname $auxiliaryfile]
  133.     set auxiliaryfile  $rootauxiliaryfile
  134.     append auxiliaryfile ".aux"
  135.     if {[file exists $auxiliaryfile] == 0} {
  136.         beep
  137.         alertnote "No AUX file found!"
  138.         return
  139.     }
  140.     set idaux [open $auxiliaryfile r]
  141.     set count -1
  142.     while {$count == -1} {
  143.         set testeof [gets $idaux buffer]
  144.         if {$testeof == -1} then {
  145.             beep
  146.             alertnote "No bibdata file found!"
  147.             return
  148.         }
  149.         set count [string first "\\bibdata" $buffer]
  150.         if {$count >= 0} then {
  151.             set bibdata [split $buffer ,]
  152.             set len [llength $bibdata]
  153.             if {$len == 1} then {
  154.                 beep
  155.                 alertnote "No other AUX files found!"
  156.                 return
  157.             }
  158.         }
  159.   }
  160.  
  161.     # It exists many bibdata and .aux files
  162.     # Building the list of all the .aux files
  163.     
  164.     set auxiliaryfile [lindex [winNames -f] 0]
  165.     set dirauxiliaryfile [file dirname $auxiliaryfile]
  166.     set rootauxiliaryfile [file rootname $auxiliaryfile]
  167.     set listauxiliaryfile [glob -nocomplain "$rootauxiliaryfile.?.aux"]
  168.     set listauxiliaryfile [map "file tail" $listauxiliaryfile]
  169.     
  170.     # End of building the list of .aux files
  171.     #
  172.     set selectauxiliary [listpick -p "bibtex:" [lsort $listauxiliaryfile] ]
  173.     set filename $dirauxiliaryfile
  174.     append filename ":$selectauxiliary"
  175.     bibtexAUXFile $filename
  176. }
  177.  
  178. # Load the new Typeset submenu:
  179. eval [typesetSubmenu]
  180.